package com.crm.dao.mapper.customMapper.spiderCustomMapper;

import com.crm.model.vo.situationAware.SpiderDataVO;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.jdbc.core.SqlProvider;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author yuanyunfeng
 * @date 2021/6/3 9:57
 */
@Repository
public interface SpiderCustomMapper {

    @SelectProvider(type=SqlProvider.class,method = "querySpiderList")
    public List<SpiderDataVO> querySpiderList(String companyName);


    class SqlProvider{
        public String querySpiderList(String companyName){
            SQL sql = new SQL().SELECT("id,company_name as companyName,\n" +
                    "\tcompany_person as companyPerson,\n" +
                    "\tcompany_tel as companyTel,\n" +
                    "\tcompany_phone as companyPhone,\n" +
                    "\tcompany_desc as companyDesc,\n" +
                    "\tcompany_create_time as companyCreateTime").FROM("company_spider");
            if(StringUtils.isNoneBlank(companyName)){
                sql.WHERE("company_name like concat('%',#{companyName},'%')");
            }
            sql.ORDER_BY("make_time desc");
            return sql.toString();
        }
    }

}
